function saveMultipleFigures( figures, ftitles, portraitTf )
%SAVEMULTIPLEFIGURES 

if isempty(ftitles)
    tempFilenameBase = char(System.Guid.NewGuid().ToString);
    for fI = 1:length(figures)
        file{fI} = savePsFigure(figures(fI), ['~' tempFilenameBase ' (' num2str(fI) ')'], portraitTf);
    end
else
    for fI = 1:length(figures)
        file{fI} = savePsFigure(figures(fI), ['~' ftitles{fI} ' (' num2str(fI) ')'], portraitTf);
    end
end

disp(file');
end

function name = savePsFigure( fig, name, portraitTf )
%SAVEFIGURE Don't include the extension in name!

% Remove illigal characters..
name([find(name=='/') find(name==';') find(name=='\') find(name=='?') find(name=='*') ]) = '_';

set(fig, 'PaperUnits', 'centimeters');
set(fig, 'PaperType', 'A4');
if exist('portraitTf') && portraitTf
    set(fig, 'PaperOrientation', 'portrait');
    set(fig, 'PaperPositionMode', 'manual');
%     set(fig, 'PaperPosition', [0.6 0.6 13 19.5]);
    set(fig, 'PaperPosition', [0.6 0.6 19.7 28.4]);
else
    set(fig, 'PaperOrientation', 'landscape');
    set(fig, 'PaperPositionMode', 'manual');
%     set(fig, 'PaperPosition', [0.6 0.6 19.5 13]);
    set(fig, 'PaperPosition', [0.6 0.6 28.4 19.7]);
end

saveas(fig, [name '.ai'], 'ai')
% print(['-f' num2str(fig)], [path name '.eps'], '-depsc', '-r600');
print(['-f' num2str(fig)], [path name '.png'], '-dpng', '-r600');
% print(['-f' num2str(fig)], [name '.pdf'], '-dpdf', '-r600');
print(['-f' num2str(fig)], [name '.pdf'], '-dpdf', '-r600');

end